<template>
        <el-dialog title="编辑问题日志" :visible.sync="editDialogVisible">
            <el-form ref="formEdit" :model="formEdit" label-width="80px">
              <el-form-item label="问题标题">
              <el-input v-model="formEdit.name"></el-input>
              </el-form-item>
              <el-form-item label="班组">
              <el-select v-model="formEdit.region_name" placeholder="请选择班组">
                <el-option label="调度组" value="调度组"></el-option>
                <el-option label="库房组" value="库房组"></el-option>
                <el-option label="产线技术组" value="产线技术组"></el-option>
                <el-option label="数控一组" value="数控一组"></el-option>
                <el-option label="数控二组" value="数控二组"></el-option>
                <el-option label="数控三组" value="数控三组"></el-option>
               </el-select>
              </el-form-item>
              <el-form-item label="问题分类" style=" display: block;">
                <template>
                  <el-radio v-model="formEdit.problem_type" label="信息化异常">信息化异常</el-radio>
                  <el-radio v-model="formEdit.problem_type" label="生产协调">生产协调</el-radio>
                </template>
              </el-form-item>
              <el-form-item label="问题描述" style=" display: block;">
                <el-input type="textarea" v-model="formEdit.description" style="width: 500px;"></el-input>
              </el-form-item>
              <el-form-item label="解决思路" style=" display: block;">
                <el-input type="textarea" v-model="formEdit.solution" style="width: 500px;"></el-input>
              </el-form-item>
              <el-form-item label="解决状态">
                <el-switch
                v-model="formEdit.is_solved"
                active-color="#13ce66"
                inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button style="background-color: rgb(37, 108, 155);" type="primary" @click="editDialogVisible = false">取 消</el-button>
              
                <el-button style="background-color: rgb(37, 108, 155);" type="primary" @click="emitEdit">提交</el-button>
            </div>
          </el-dialog>
</template>
<script>
export default{
    props: {
        tableData: {
            type: Array,
            required: true
        }
    },
    data(){
        return{
          dialogImageUrl: '',
        dialogVisible: false,
            editDialogVisible:false,
            index:Number,
            formEdit: {
                log_id:Number,
                name: '',
                region_name: '',
                problem_type: [],
                date:null,
                description: '',
                solution: '',
                is_solved:false
            },
        }
    },
    methods:{
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
         // 数据回显
        openEditDialog(index) {
            console.log("数据回显")
            this.formEdit.log_id = this.tableData[index].log_id;
            this.formEdit.date = this.tableData[index].date;
            this.formEdit.name = this.tableData[index].name;
            this.formEdit.region_name = this.tableData[index].region_name;
            this.formEdit.problem_type = this.tableData[index].problem_type;
            this.formEdit.description = this.tableData[index].description;
            this.formEdit.solution = this.tableData[index].solution;
            this.formEdit.is_solved = this.tableData[index].is_solved;
            this.editDialogVisible = true;
            this.index = index;
            //console.log(this.formEdit.date)
          },
        // 发送编辑事件
        emitEdit() {
            console.log("发送编辑事件给父组件")
            const editedItem = {
              date: this.formEdit.date,
              log_id: this.formEdit.log_id,
              name: this.formEdit.name,
              region_name: this.formEdit.region_name,
              problem_type: this.formEdit.problem_type,
              description: this.formEdit.description,
              solution: this.formEdit.solution,
              is_solved: this.formEdit.is_solved
          };
          //console.log(editedItem.date)
          this.$emit('handleEditEvent', editedItem,this.index);
          this.editDialogVisible = false;
        }
    }
}
</script>